package top.lixunda.ecommerce.server.user.api.entity.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;
import top.lixunda.common.validate.annotation.XumDefault;
import top.lixunda.common.validate.annotation.XumIncludes;
import top.lixunda.common.validate.annotation.XumMax;
import top.lixunda.common.validate.annotation.XumNotNull;
import top.lixunda.ecommerce.server.user.api.entity.db.StoreAddressDO;
import top.lixunda.ecommerce.server.user.api.entity.db.UserAddressDO;

import java.time.LocalDateTime;

/**
 * @author Xumda
 * @version time:2019/12/14 22:13
 * <p>
 * 更改商铺用户地址信息时的DTO
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class StoreAddressChgDTO {

    @XumNotNull
    private Integer id;

    @XumNotNull
    private Integer provinceId;

    @XumNotNull
    private String name;

    @XumNotNull
    private String provinceName;

    @XumNotNull
    private Long cityId;

    @XumNotNull
    private String cityName;

    @XumNotNull
    private Long countyId;

    @XumNotNull
    private String countyName;

    @XumNotNull
    @XumMax(255)
    private String detail;

    @XumNotNull
    @XumIncludes(numbers = {0, 1})
    private Integer isDefault;

    @XumNotNull
    @XumDefault("")
    private String remark;

    @XumNotNull
    @XumDefault("")
    private String postalCode;

    @XumNotNull
    private String phone;

    @XumNotNull
    private String username;

    @SuppressWarnings("Duplicates")
    public StoreAddressDO toStoreAddress() {
        StoreAddressDO storeAddress = new StoreAddressDO();
        storeAddress.setId(this.id);
        storeAddress.setName(this.name);
        storeAddress.setProvinceId(this.provinceId);
        storeAddress.setProvinceName(this.provinceName);
        storeAddress.setCityId(this.cityId);
        storeAddress.setCityName(this.cityName);
        storeAddress.setCountyId(this.countyId);
        storeAddress.setCountyName(this.countyName);
        storeAddress.setDetail(this.detail);
        storeAddress.setUsername(this.username);
        storeAddress.setPhone(this.phone);
        storeAddress.setPostalCode(this.postalCode);
        storeAddress.setUseable(UserAddressDO.USEABLE);
        storeAddress.setIsDefault(this.isDefault);
        storeAddress.setRemark(this.remark);
        LocalDateTime now = LocalDateTime.now();
        storeAddress.setUpdateTime(now);
        return storeAddress;
    }
}
